import { IFeidaoAiNodejsPage, IWebResult } from '../../interfaces';
import is_online from '../msg/user-isonline';
import generate from '../url/query2url';

export default async function check(fd: IFeidaoAiNodejsPage, fallback: string) {
	const { actionid, sessionid, msg, url } = fd.data;
	const line = await is_online(actionid, sessionid, msg);
	if (line) {
		return {} as IWebResult;
	} else {
		const page_name = url.match(/.*\/((.*?)\.html)/)![1];
		const params = url.includes('?') ? url.substr(url.indexOf('?')) : '';
		const obj = {
			backurl: './' + page_name + params
		};
		const redirect = generate(obj, fallback);
		return {
			code: 0,
			redirect
		} as IWebResult;
	}
}
